<!--- extract all Forms --->

<CFQUERY NAME="GetForm" DATASOURCE="#client.company_dsn#">
	SELECT DISTINCT
		TABLENAME_FK, PK_FIELD1, PK_FIELD2,
		PK_FIELD3, PK_FIELD4, PK_FIELD5
	FROM ECRGFORMS
	WHERE (FORMCODE  = '#theFormCode#')
</CFQUERY>

<CFQUERY NAME="GetData" DATASOURCE="#client.company_dsn#">
	SELECT * FROM CINWORKSCHED
	WHERE WSCODE_FK = '#sID#'
		AND WSNUMBER='#wsIDnum#'
</CFQUERY>
<CFQUERY NAME="GetDTLmaster" DATASOURCE="#client.company_dsn#">
	SELECT * FROM CINWSMASTERPOOL
	WHERE WSNUMBER_FK='#wsIDnum#'
</CFQUERY>
<CFQUERY NAME="GetDTLsubtemp" DATASOURCE="#client.company_dsn#">
	SELECT * FROM CINWSSUBSKEDPOOL
	WHERE WSNUMBER_FK='#wsIDnum#'
		AND (PATTERNCODE IS NOT NULL AND PATTERNCODE != '')
</CFQUERY>
<CFQUERY NAME="GetDTLtemp" DATASOURCE="#client.company_dsn#">
	SELECT * FROM CINWSTEMPSKEDPOOL
	WHERE WSNUMBER_FK='#wsIDnum#'
</CFQUERY>

<CFSET formCode=urlEncodedFormat(encrypt("#theFormCode#",client.ek))>

<CFIF GetDTLmaster.RECORDCOUNT OR GetDTLtemp.RECORDCOUNT OR GetDTLsubtemp.RECORDCOUNT>
	<!--- get the values of the indexed fields --->
	<CFSET sUFValue = "">
	<CFLOOP  INDEX="x" FROM="1" TO="5">
		<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
			<CFSET sUFValue = sUFValue & "&" & lcase(evaluate("GetForm.PK_FIELD" & x)) & "=" & evaluate("GetData." & evaluate("GetForm.PK_FIELD" & x))>
		</CFIF>
	</CFLOOP>
	
	<CFLOCATION url="#client.domain#eforms/perid_idx/index.cfm?id=#formCode##sUFValue#&edit=">
<CFELSE>
	<CFSET sIDUrlEnc = URLEncodedFormat(Encrypt(sID,client.ek))>
	<CFSET idDetVal = URLEncodedFormat(Encrypt(wsIDnum,client.ek))>
	<CFSET actEdit=urlEncodedFormat(encrypt("edit", client.ek))>
	<CFSET actPosted = URLEncodedFormat(encrypt("No",client.ek))>
	
	<CFLOCATION url="#client.domain#eworksched/wsmain/index.cfm?id=#sIDUrlEnc#&wsnum=#idDetVal#&myAction=#actEdit#&posted=#actPosted#&notroute=">
</CFIF>


